package com.tedu.m1;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/11/26
 */
public class Consumer {

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory c = new ConnectionFactory();
        c.setHost("192.168.126.129");
        c.setUsername("admin");
        c.setPassword("admin");
        Connection connection = c.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("helloword", false, false, false, null);
        DeliverCallback deliverCallback = new DeliverCallback() {
            @Override
            public void handle(String consumerTag, Delivery message) throws IOException {
                String msg = new String(message.getBody(), "UTF-8");
                System.out.println("收到: "+msg);
            }
        };

        CancelCallback cancelCallback = new CancelCallback() {
            @Override
            public void handle(String consumerTag) throws IOException {

            }
        };
        channel.basicConsume("helloword", true,deliverCallback,cancelCallback);
    }
}
